Constraints:

UNIQUE:
Apply UNIQUE constraint through CREATE table statement:
Ans:
create table SAMPLE (ID number(4) constraint UNQ1 UNIQUE,
NAME varchar2(10), CITY varchar2(10), AGE number(2), GENDER char(1));

insert records:
insert into sample values(1001, 'ARJUN', 'RAICHUR', 21, 'M');

Try to insert dublicate values into ID column. Then we get below error:
unique constraint (SYSTEM.UNQ1) violated

Q: How to check unique constraint is applied on the SAMPLE table id column?
Ans: you need to query USER_CONSTRAINTS table.

select CONSTRAINT_NAME, CONSTRAINT_TYPE, TABLE_NAME, STATUS from
USER_CONSTRAINTS where table_name='SAMPLE';

Q: How to disable, enable OR drop the UNIQUE constraint?
Ans:
alter table SAMPLE disable constraint UNQ1;
alter table SAMPLE enable constraint UNQ1;
alter table SAMPLE drop constraint UNQ1;

Apply UNIQUE constraint through ALTER table statement:
Ans:
alter table SAMPLE add constraint UNQ2 UNIQUE(ID);

Note: Here also we can enable, disable and drop the constraint and validate accordingly against USER_CONSTRAINTS table
*****************************************************************************

NOT NULL: 
Apply NOT NULL constraint through CREATE table statement:
Ans:
create table SAMPLE (ID number(4),
NAME varchar2(10) constraint nn1 NOT NULL, CITY varchar2(10), 
AGE number(2), GENDER char(1));

Now try to insert null value into NAME column viz.,
insert into sample values(1001, '', 'RAICHUR', 21, 'M');

It will throw below error:
cannot insert NULL into ("SYSTEM"."SAMPLE"."NAME")

Q: How to check not null constraint is applied on the SAMPLE table name column?
Ans: you need to query USER_CONSTRAINTS table.

select CONSTRAINT_NAME, CONSTRAINT_TYPE, TABLE_NAME, STATUS from
USER_CONSTRAINTS where table_name='SAMPLE';

Q: How to disable, enable OR drop the NOT NULL constraint?
Ans:
alter table SAMPLE disable constraint NN1;
alter table SAMPLE enable constraint NN1;
alter table SAMPLE drop constraint NN1;

Apply NOT NULL constraint through ALTER table statement:
Ans:
alter table SAMPLE modify (NAME varchar2(10) constraint nn2 NOT NULL);

Note: Here also we can enable, disable and drop the constraint and validate accordingly against USER_CONSTRAINTS table
*****************************************************************************

CHECK:

Apply CHECK constraint through CREATE table statement:
Ans:
create table SAMPLE (ID number(4),
NAME varchar2(10), CITY varchar2(10), 
AGE number(2) constraint chk1 CHECK (age>=18 and age<=99), GENDER char(1));

Now try to insert invalid age value into AGE column viz.,
insert into SAMPLE values(1001, 'ARJUN', 'RAICHUR', 15, 'M')

It will throw below error:
check constraint (SYSTEM.CHK1) violated

Q: How to check unique constraint is applied on the SAMPLE table age column?
Ans: you need to query USER_CONSTRAINTS table.

select CONSTRAINT_NAME, CONSTRAINT_TYPE, TABLE_NAME, STATUS from
USER_CONSTRAINTS where table_name='SAMPLE';

Q: How to disable, enable OR drop the CHECK constraint?
Ans:
alter table SAMPLE disable constraint CHK1;
alter table SAMPLE enable constraint CHK1;
alter table SAMPLE drop constraint CHK1;


Apply CHECK constraint through ALTER table statement:
Ans:
alter table SAMPLE add constraint chk2 CHECK (age>=18 and age<=99);
alter table SAMPLE add constraint chk2 CHECK (age between 18 and 99);

Note: Here also we can enable, disable and drop the constraint and validate accordingly against USER_CONSTRAINTS table
***************************************************************************

PRIMARY KEY (PK):

Apply PK constraint through CREATE table statement:
Ans:
create table SAMPLE (ID number(4) constraint pk PRIMARY KEY,
NAME varchar2(10), CITY varchar2(10), 
AGE number(2), GENDER char(1));


Now try to insert invalid (null OR duplicate) value into ID column viz.,
insert into SAMPLE values('', 'ARJUN', 'RAICHUR', 21, 'M');

It will throw below error:
cannot insert NULL into ("SYSTEM"."SAMPLE"."ID")

If we try to insert duplicate value into ID column viz.,
insert into SAMPLE values(1001, 'BALARAM', 'MYSORE', 21, 'M');

It will throw below error:
unique constraint (SYSTEM.PK) violated


Q: How to check PK constraint is applied on the SAMPLE table ID column?
Ans: you need to query USER_CONSTRAINTS table.

select CONSTRAINT_NAME, CONSTRAINT_TYPE, TABLE_NAME, STATUS from
USER_CONSTRAINTS where table_name='SAMPLE';

Q: How to disable, enable OR drop the PK constraint?
Ans:
alter table SAMPLE disable constraint pk;
alter table SAMPLE enable constraint pk;
alter table SAMPLE drop constraint pk;


Apply PK constraint through ALTER table statement:
Ans:
alter table SAMPLE add constraint PKK PRIMARY KEY(ID);


Q: How to apply composite PK to ID columns?
Ans:
alter table SAMPLE add constraint PKK PRIMARY KEY(ID, NAME);

Note: Here also we can enable, disable and drop the constraint and validate accordingly against USER_CONSTRAINTS table
***************************************************************************

FOREIGN KEY:

Pre-Requisite:
First we must have a parent (STUDENT) table with PK applied on ID column:

create table STUDENT (ID number(4) constraint PK PRIMARY KEY,
NAME varchar2(10), CITY varchar2(10), age number(2), GENDER char(1));

insert few records:
insert into STUDENT values(1001, 'ARJUN', 'RAICHUR', 21, 'M');
insert into STUDENT values(1002, 'BALARAAM', 'GADAG', 21, 'M');
insert into STUDENT values(1003, 'CHANAKYA', 'MYSORE', 21, 'M');
insert into STUDENT values(1004, 'DAMAYANTHI', 'MYSORE', 21, 'F');
insert into STUDENT values(1005, 'RADHE', 'BANGALORE', 21, 'F');

Now create child table using create table statement (LIBRARY) with FK constraint applied on ID column:

create table LIBRARY(ID number(4), constraint fk FOREIGN KEY(id) 
references STUDENT(ID), BOOKS varchar(10), 
AUTHOR varchar2(10), IssueDate date);


Q: How to check FK constraint is applied on the LIBRARY table ID column?
Ans: you need to query USER_CONSTRAINTS table.

select CONSTRAINT_NAME, CONSTRAINT_TYPE, TABLE_NAME, STATUS from
USER_CONSTRAINTS where table_name='LIBRARY';

Q: How to disable, enable OR drop the PK constraint?
Ans:
alter table SAMPLE disable constraint pk;
alter table SAMPLE enable constraint pk;
alter table SAMPLE drop constraint pk;


Apply FK constraint through ALTER table statement:
Ans:
alter table LIBRARY add constraint FK FOREIGN KEY(ID) references STUDENT(ID);

Note: Here also we can enable, disable and drop the constraint and validate accordingly against USER_CONSTRAINTS table

